<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){
        $this->display();
    }
    public function login(){
        //检验验证码
        $verify = new \Think\Verify();
        if($verify->check(I('verify'))==false){
            $this->error("验证码错误");
        }
        $User=D('User');
        if($User->create()){
            $username=I('username');
            $password=md5(I('password'));
            if($User->where("`username`='$username' and `password`='$password'")->find()){//验证为真，登录成功
                session('username',$username);
                redirect(U('/Home/Index/index'),0,'登录中.....');
            }else{
                //登录失败
                echo $User->getLastSql();
                exit();
                $this->error('用户名或密码错误');
            }
        }else{
            //验证没有通过
            $this->error($User->getError());
        }
    }
}